VERSION 5.00
Begin VB.Form frmConnectionString 
   Caption         =   "Open a Connection"
   ClientHeight    =   7590
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   4470
   LinkTopic       =   "Form1"
   ScaleHeight     =   7590
   ScaleWidth      =   4470
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "DSN-Less Connection String to ODBC Drivers"
      Height          =   2415
      Left            =   120
      TabIndex        =   8
      Top             =   2520
      Width           =   4215
      Begin VB.CommandButton cmdOracleODBCDSNless 
         Caption         =   "Oracle ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   10
         Top             =   960
         Width           =   3915
      End
      Begin VB.CommandButton cmdSQLServerODBCDSNless 
         Caption         =   "SQL Server ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   11
         Top             =   1680
         Width           =   3915
      End
      Begin VB.CommandButton cmdJetODBCDSNless 
         Caption         =   "Access ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   9
         Top             =   240
         Width           =   3915
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "DSN Connection String to ODBC Drivers"
      Height          =   2415
      Left            =   120
      TabIndex        =   0
      Top             =   0
      Width           =   4215
      Begin VB.CommandButton cmdOracleODBCDSN 
         Caption         =   "Oracle ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   2
         Top             =   960
         Width           =   3915
      End
      Begin VB.CommandButton cmdSQLServerODBCDSN 
         Caption         =   "SQL Server ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   3
         Top             =   1680
         Width           =   3915
      End
      Begin VB.CommandButton cmdJetODBCDSN 
         Caption         =   "Access ODBC Driver"
         Height          =   615
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   3915
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Connection String to Native OLE DB Providers"
      Height          =   2415
      Left            =   120
      TabIndex        =   4
      Top             =   5040
      Width           =   4215
      Begin VB.CommandButton cmdOracleNativeProvider 
         Caption         =   "Oracle OLE DB Native Provider"
         Height          =   615
         Left            =   120
         TabIndex        =   6
         Top             =   960
         Width           =   3915
      End
      Begin VB.CommandButton cmdSQLServerNativeProvider 
         Caption         =   "SQL Server OLE DB Native Provider"
         Height          =   615
         Left            =   120
         TabIndex        =   7
         Top             =   1680
         Width           =   3915
      End
      Begin VB.CommandButton cmdJetNativeProvider 
         Caption         =   "Jet OLE DB Native Provider"
         Height          =   615
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   3915
      End
   End
End
Attribute VB_Name = "frmConnectionString"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim con1 As ADODB.Connection

Private Sub Con1_Open(ConnectString As String)
    
    Set con1 = New ADODB.Connection
    
    On Error GoTo theexit
  
    con1.Open ConnectString
 
    MsgBox ("Success!")
    con1.Close
    Set con1 = Nothing
    Exit Sub
  
theexit:
    
    MsgBox ("Ooops! We failed to connect!")
    On Error GoTo 0
    Set con1 = Nothing
End Sub

Private Sub cmdJetODBCDSN_Click()
    ' This code assumes that the ODBC Data Source OLE_DB_NWind_Jet
    ' was created by the installation of the DATA ACCESS 2.0 SDK.
    ' Please create manually if it doesn't exist
    

    ' Access ODBC Driver via DSN
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DSN=OLE_DB_NWind_Jet;" & _
              "UID=admin;PWD=;"
              
    Con1_Open "DSN=OLE_DB_NWind_Jet;" & _
              "UID=admin;PWD=;"
              
    ' Access ODBC Driver via DSN using ADO Syntax
    ' Note use of DATA SOURCE=, USER ID=, and PASSWORD= clauses
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DATA SOURCE=OLE_DB_NWind_Jet;" & _
              "USER ID=admin;PASSWORD=;"
    
    Con1_Open "DATA SOURCE=OLE_DB_NWind_Jet;" & _
              "USER ID=admin;PASSWORD=;"
End Sub

Private Sub cmdOracleODBCDSN_Click()
    ' This code assumes you have Oracle Client software installed,
    ' that you have an oracle Server named "dseOracle8" and that
    ' you have an ODBC Data Source named "dseOracleDSN" that
    ' references this server.
    
    ' Oracle ODBC Driver via DSN
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DSN=dseOracleDSN;" & _
              "UID=demo;PWD=demo;"
    
    Con1_Open "DSN=dseOracleDSN;" & _
              "UID=demo;PWD=demo;"
    
    ' Oracle ODBC Driver via DSN using ADO Syntax
    ' Note use of DATA SOURCE=, USER ID=, and PASSWORD= clauses
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DATA SOURCE=dseOracleDSN;" & _
              "USER ID=demo;PASSWORD=demo;"
    
    Con1_Open "DATA SOURCE=dseOracleDSN;" & _
              "USER ID=demo;PASSWORD=demo;"

End Sub

Private Sub cmdSQLServerODBCDSN_Click()
    ' This code assumes you have SQL Server installed with
    ' an ODBC Data Source named "LocalServer"
  
    ' SQL Server ODBC Driver via DSN
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DSN=LocalServer;database=Master;" & _
              "UID=sa;pwd=;"
              
    Con1_Open "DSN=LocalServer;database=Master;" & _
              "UID=sa;pwd=;"
              
    ' SQL Server ODBC Driver via DSN using ADO syntax
    ' Note use of DATA SOURCE=, INITIAL CATALOG=, USER ID=, and PASSWORD= clauses
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DATA SOURCE=LocalServer;INITIAL CATALOG=pubs;" & _
              "USER ID=sa;PASSWORD=;"
    
    Con1_Open "DATA SOURCE=LocalServer;INITIAL CATALOG=pubs;" & _
              "USER ID=sa;PASSWORD=;"

End Sub

Private Sub cmdJetODBCDSNless_Click()
    ' This code assumes you have the NWIND access database
    ' in a path C:\_data

    '  Access ODBC Driver via DSN-Less
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DRIVER={Microsoft Access Driver (*.mdb)};" & _
              "DBQ=C:\_data\NWind.mdb;" & _
              "UID=sa;PWD=;"

    Con1_Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
              "DBQ=C:\_data\NWind.mdb;" & _
              "UID=sa;PWD=;"

End Sub


Private Sub cmdOracleODBCDSNless_Click()
    ' This code assumes you have Oracle Client software installed,
    ' that you have an oracle Server named "dseOracle8"
   
    '  Oracle ODBC Driver
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DRIVER={Microsoft ODBC for Oracle};" & _
              "SERVER=dseOracle8;" & _
              "UID=demo;PWD=demo;"

    Con1_Open "DRIVER={Microsoft ODBC for Oracle};" & _
              "SERVER=dseOracle8;" & _
              "UID=demo;PWD=demo;"
End Sub


Private Sub cmdSQLServerODBCDSNless_Click()
    ' This code assumes you have SQL Server named "zhadumnt"

    '  SQL Server ODBC Driver
    Con1_Open "PROVIDER=MSDASQL;" & _
              "DRIVER={SQL Server};" & _
              "SERVER=zhadumnt;DATABASE=pubs;" & _
              "UID=sa;PWD=;"

    Con1_Open "DRIVER={SQL Server};" & _
              "SERVER=zhadumnt;DATABASE=pubs;" & _
              "UID=sa;PWD=;"
End Sub

Private Sub cmdJetNativeProvider_Click()
    ' This code assumes you have the NWIND access database
    ' in a path C:\_data

    ' Access Provider
    ' NOTE:  UID and PWD syntax cannot be used here
    Con1_Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
              "DATA SOURCE=C:\_data\NWind.mdb;" & _
              "USER ID=admin;PASSWORD=;"

End Sub

Private Sub cmdOracleNativeProvider_Click()
    ' This code assumes you have Oracle Client software installed,
    ' that you have an oracle Server named "dseOracle8"

    '  Oracle Provider
    Con1_Open "PROVIDER=MSDAORA;" & _
              "DATA SOURCE=dseOracle8;" & _
              "USER ID=demo;PASSWORD=demo;"

End Sub

Private Sub cmdSQLServerNativeProvider_Click()
    ' This code assumes you have SQL Server named "zhadumnt"
    
    '  SQL Server Provider
    Con1_Open "PROVIDER=SQLOLEDB;" & _
              "DATA SOURCE=zhadumnt;DATABASE=pubs;" & _
              "USER ID=sa;PASSWORD=;"
    
    '  SQL Server Provider (using ODBC Syntax)
    Con1_Open "PROVIDER=SQLOLEDB;" & _
              "DSN=zhadumnt;DATABASE=pubs;" & _
              "UID=sa;PWD=;"
End Sub

